﻿using SHomeWorkshop.LunarSF.StudentInfosManager.ValidationRules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace SHomeWorkshop.LunarSF.StudentInfosManager
{
    public class Settings : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// 属性值发生变化时产生通知事件。
        /// </summary>
        public void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(sender, e);
            }
        }

        internal void SaveToConfigManager(XmlConfigManager manager)
        {
            if (manager == null)
                throw new ArgumentNullException("manager 不能为 null 。");

            manager.Set("SchoolName", this.SchoolName);
            manager.Set("GradesCount", this.GradesCount.ToString());
        }

        string schoolName;
        /// <summary>
        /// 校名。
        /// </summary>
        public string SchoolName
        {
            get { return NameRule.Format(schoolName); }
            set
            {
                schoolName = value;
                OnPropertyChanged(this, new PropertyChangedEventArgs("SchoolName"));
            }
        }

        int gradesCount = 3;

        /// <summary>
        /// 本校有几个年级。
        /// </summary>
        public int GradesCount
        {
            get { return gradesCount; }
            set
            {
                gradesCount = value;
                OnPropertyChanged(this, new PropertyChangedEventArgs("GradesCount"));
            }
        }
    }
}
